package task1

/**
 * @author jhhe66
 * @date 2021/6/18 9:57
 */
object WordCountScalaBatch {
  def main(args: Array[String]): Unit = {
    import org.apache.flink.api.scala._
    val inputPath = "data/input/input.txt"
    val outputPath = "data/output/output.csv"

    val env: ExecutionEnvironment = ExecutionEnvironment.createCollectionsEnvironment
    val ds1: DataSet[String] = env.readTextFile(inputPath)
    val ret: AggregateDataSet[(String, Int)] = ds1.flatMap(_.split(" "))
      .map((_, 1))
      .groupBy(0)
      .sum(1)

    ret.writeAsCsv(outputPath)

    env.execute()
  }
}
